package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.InformationEntry;
import com.pureut.system.domain.MaterialScrapManagement;
import com.pureut.system.domain.MesRepairManagement;
import com.pureut.system.domain.vo.MaterialScrapManagementVo;
import com.pureut.system.service.IMaterialScrapManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-08 13:41:29
 * @Desc: 物料报废管理表Controller
 */
@RestController
@RequestMapping("/system/materialScrapManagement")
public class MaterialScrapManagementController extends BaseController {

    /**
     * 物料报废管理表Service
     */
    @Resource
    private IMaterialScrapManagementService materialScrapManagementService;

    /**
     * 查询物料报废管理表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialScrapManagement-list")
    @GetMapping("/list")
    public TableDataInfo list( MaterialScrapManagementVo materialScrapManagementVo) {
        startPage();
        LambdaQueryWrapper<MaterialScrapManagement> resultQuery = new LambdaQueryWrapper<MaterialScrapManagement>();
        if(ObjectUtil.isNotNull(materialScrapManagementVo.getCreateBy())){
            resultQuery.like(MaterialScrapManagement::getCreateBy, materialScrapManagementVo.getCreateBy());
        }
        if(ObjectUtil.isNotNull(materialScrapManagementVo.getMaterialCode())){
            resultQuery.like(MaterialScrapManagement::getMaterialCode, materialScrapManagementVo.getMaterialCode());
        }
        if(ObjectUtil.isNotNull(materialScrapManagementVo.getStartTime())&&ObjectUtil.isNotNull(materialScrapManagementVo.getEndTime())){
            resultQuery.between(MaterialScrapManagement::getCreateTime, materialScrapManagementVo.getStartTime(),materialScrapManagementVo.getEndTime());
        }
        return getDataTable(materialScrapManagementService.list(resultQuery));
    }


    /**
     * 获取物料报废管理表详细信息
     * @param: id 物料报废管理表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialScrapManagement-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(materialScrapManagementService.getById(id));
    }

    /**
     * 新增物料报废管理表
     * @param: materialScrapManagement 物料报废管理表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialScrapManagement-add")
    @PostMapping
    public AjaxResult add(@RequestBody MaterialScrapManagementVo materialScrapManagementVo) {
        return toAjax(materialScrapManagementService.save(materialScrapManagementVo));
    }

    /**
     * 修改物料报废管理表
     * @param: materialScrapManagement 物料报废管理表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialScrapManagement-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody MaterialScrapManagementVo materialScrapManagementVo) {
        return toAjax(materialScrapManagementService.updateById(materialScrapManagementVo));
    }

    /**
     * 删除物料报废管理表
     * @param: id 物料报废管理表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialScrapManagement-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialScrapManagementService.removeByIds(Arrays.asList(ids)));
    }
}
